using System.IO;

namespace TomNet.Attributes
{
    public class NumberRangeAttribute : BaseAttribute
    {

        public int Min { get; set; }
        public int Max { get; set; }

        public override string Error
        {
            get
            {
                if (base.Error != null)
                {
                    return base.Error;
                }
                return $"数字超过了有效范围[{Min}] - [{Max}]";
            }

            set => base.Error = value;
        }


        public override bool Validate(object value)
        {
            return value == null || value switch
            {
                int val => val >= Min && val <= Max,
                decimal val => val >= Min && val <= Max,
                long val => val >= Min && val <= Max,
                _ => throw new InvalidDataException()
            };
        }
    }
}